#include <QValidator>
#include <QRegExp>

#include "LoginDialog.hpp"
#include "ui_LoginDialog.h"

LoginDialog::LoginDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LoginDialog)
{
    ui->setupUi(this);
    ui->m_portEdit->setValidator(
                new QRegExpValidator(QRegExp("(\\d+)"), this));
    ui->m_IPEdit->setValidator(
                new QRegExpValidator(
                    QRegExp("((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(localhost)"),
                    this));
    ui->m_IPEdit->setText("127.0.0.1");
    ui->m_portEdit->setText("5555");

#ifdef _DEBUG
    ui->m_nameEdit->setText("admin");
    ui->m_paswordEdit->setText("admin");
#endif
}

LoginDialog::~LoginDialog()
{
    delete ui;
}

QString LoginDialog::getIP() const
{
    return ui->m_IPEdit->text();
}

QString LoginDialog::getPort() const
{
    return ui->m_portEdit->text();
}

QString LoginDialog::getName() const
{
    return ui->m_nameEdit->text();
}

QString LoginDialog::getPassword() const
{
    return ui->m_paswordEdit->text();
}
